<template>
  <div class="common-layout">
    <el-container>
      <el-header height="60px" class="header">
        <div class="header-content">
          <h2>会议室预订系统 - 员工端</h2>
          <div class="header-actions">
            <el-button type="primary" @click="handleLogout">退出登录</el-button>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px" class="aside">
          <el-menu :default-active="activeTab" class="side-menu" @select="handleTabChange">
            <el-menu-item index="roomStatus">
              <span>会议室状态预览</span>
            </el-menu-item>
            <el-menu-item index="reservations">
              <span>订单管理</span>
            </el-menu-item>
            <el-menu-item index="cancellationApproval">
              <span>取消预订审核</span>
            </el-menu-item>
            <el-menu-item index="profile">
              <span>个人资料</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main class="main-content">
          <div class="dashboard-content">
            <el-tabs v-model="activeTab" class="dashboard-tabs">
              <el-tab-pane label="会议室状态预览" name="roomStatus">
                <MeetingRoomStatusView ref="roomStatusRef" />
              </el-tab-pane>
              <el-tab-pane label="订单管理" name="reservations">
                <ReservationManagementView ref="reservationsRef" />
              </el-tab-pane>
              <el-tab-pane label="取消预订审核" name="cancellationApproval">
                <CancellationApprovalView ref="cancellationRef" />
              </el-tab-pane>
              <el-tab-pane label="个人资料" name="profile">
                <ProfileView />
              </el-tab-pane>
            </el-tabs>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { ElPageHeader, ElButton, ElTabs, ElTabPane } from 'element-plus'
import { useAuthStore } from '@/stores/auth'
import MeetingRoomStatusView from './MeetingRoomStatusView.vue'
import CancellationApprovalView from './CancellationApprovalView.vue'
import ProfileView from './ProfileView.vue'
import ReservationManagementView from './ReservationManagementView.vue'

export default {
  name: 'EmployeeDashboardView',
  components: {
    ElPageHeader,
    ElButton,
    ElTabs,
    ElTabPane,
    MeetingRoomStatusView,
    CancellationApprovalView,
    ProfileView,
    ReservationManagementView,
  },
  setup() {
    const authStore = useAuthStore()
    return { authStore }
  },
  data() {
    return {
      activeTab: 'roomStatus',
    }
  },
  methods: {
    handleTabChange(tab) {
      this.activeTab = tab
      this.$nextTick(() => {
        switch(tab) {
          case 'roomStatus':
            this.$refs.roomStatusRef?.fetchMeetingRooms()
            break
          case 'reservations':
            this.$refs.reservationsRef?.fetchReservations()
            break
          case 'cancellationApproval':
            this.$refs.cancellationRef?.fetchRequests()
            break
        }
      })
    },
    goBack() {
      this.$router.go(-1)
    },
    handleLogout() {
      this.authStore.logout()
    },
  },
}
</script>

<style scoped>
.header {
  background-color: #409eff;
  color: white;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
}

.aside {
  background-color: white;
  border-right: 1px solid #e6e6e6;
}

.side-menu {
  border-right: none;
}

.main-content {
  padding: 0;
  background-color: #f5f7fa;
}

.dashboard-content {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 60px);
}

.dashboard-tabs :deep(.el-tabs__header) {
  background-color: white;
  border-radius: 8px;
  padding: 0 24px;
  margin: 0;
}

.dashboard-tabs :deep(.el-tabs__nav-wrap) {
  padding: 0 8px;
}

.dashboard-tabs :deep(.el-tabs__item) {
  padding: 0 16px;
  height: 48px;
  line-height: 48px;
  color: #606266;
  font-weight: 500;
}

.dashboard-tabs :deep(.el-tabs__item.is-active) {
  color: #409eff;
}

.dashboard-tabs :deep(.el-tabs__item:hover) {
  color: #409eff;
}

.dashboard-tabs :deep(.el-tabs__active-bar) {
  background-color: #409eff;
}

.dashboard-tabs :deep(.el-tabs__content) {
  background-color: white;
  border-radius: 8px;
  margin-top: 16px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}
</style>
